package com.evolutioninc.wordfinder;

import java.io.IOException;
import java.util.ArrayList;


import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class SolverActivity extends ListActivity {

	protected static ArrayList<String> solution = new ArrayList<String>();
	protected WordsSolver solveWord;
	ArrayAdapter<String> adapter;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.solver);
		adapter=new ArrayAdapter<String>(this,
				android.R.layout.test_list_item,
				solution);

		ListView listView = (ListView) findViewById(android.R.id.list);
		listView.setAdapter(adapter);

	}


	public void getSolution_OnClick(View v) throws IllegalStateException, IOException
	{


		final EditText lettersField = (EditText) findViewById(R.id.EditTextLetters);
		String letters = lettersField.getText().toString();

		final EditText specialLetField = (EditText) findViewById(R.id.EditTextSpecial);
		String specialLetters = specialLetField.getText().toString();

		// Hide keyboard;
		InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(lettersField.getWindowToken(), 0);
		imm.hideSoftInputFromWindow(specialLetField.getWindowToken(), 0);

		// Get all possible answer
		//TODO sort the solution
		solution.clear();
		solution.addAll(WordsSolver.getMatchingWords(letters, specialLetters));
		adapter.notifyDataSetChanged();

		/*
    		final Spinner sortSpinner = (Spinner) findViewById(R.id.SpinnerFeedbackType);
    		String sortType = sortSpinner.getSelectedItem().toString();
		 */
	}

}
